<title>房源</title>

<div class="layui-card layadmin-header">
    <div class="layui-breadcrumb" lay-filter="breadcrumb">
        <a lay-href="">主页</a>
        <a><cite>办公</cite></a>
        <a><cite>房源</cite></a>
    </div>
</div>
<div id="room-room">
    <div class="layui-fluid">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md12">
                <div class="layui-card">
                    <div class="layui-card-body">
                        <div class="layui-btn-container">
                            <span class="layui-btn layui-btn-sm layui-btn-normal" data-type="add">添加</span>
                            <span class="layui-btn layui-btn-sm layui-btn-normal" lay-href='/room/room/'>全部</span>
                            <span class="layui-btn layui-btn-sm layui-btn-normal" data-type="search">筛选</span>


                        </div>

                    </div>
                </div>

            </div>
            <div class="layui-col-md12">
                <div id="roomlist"></div>
                <div id="pager"></div>

            </div>
        </div>
    </div>
</div>


<script id="demo1" type="text/html">

    <form class="layui-form layui-form-pane" action="">
        <div style="text-align: center;color: red;">填写小区选择条件后点击筛选</div>
        <div class="layui-form-item">
            <label class="layui-form-label">排序</label>
            <div class="layui-input-block">
                <select name="order" lay-filter="">
                    <option value="">请选择</option>
                    <option value="0">正常</option>
                    <option value="1" >置顶</option>

                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">小区名称</label>
            <div class="layui-input-block">
                <input type="text" name="keyword" autocomplete="off" placeholder="输入小区名称" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">id</label>
            <div class="layui-input-block">
                <input type="text" name="id" autocomplete="off" placeholder="输入房屋ID" class="layui-input">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label">装修</label>
            <div class="layui-input-block">
                <select name="zhuangxiu" lay-filter="">
                    <option value="">请选择</option>
                    <option value="1">毛坯</option>
                    <option value="2" >精装</option>
                    <option value="3">简装</option>


                </select>
            </div>
        </div>
        <div class="layui-form-item" style="text-align: center;">
            <button class="layui-btn" lay-submit="" lay-filter="shaixuan">筛选</button>
        </div><br><br><br><p></p>
    </form>


</script>
<script id="roomtpl" type="text/html">

    {{#  layui.each(d.data.list.data, function(index, item){ }}
    <div class="layui-card">
        <div class="layui-card-header">
            <span class="layui-badge layui-bg-gray layui-layout-right">#{{item.id}}</span>
            <p class="layui-shenglue">  {{item.title}}</p>

        </div>
        <div class="layui-card-body">
            {{item.content}}
            <p><span class="layui-badge">{{item.money}}万</span>
                <span class="layui-badge">{{item.area}}平</span>
                <span class="layui-badge">{{item.floors}}/{{item.floor}}层</span>
                <span class="layui-badge">

            {{#
              var text = "";
              switch(item.xuequ)
{
case 1:
 text='东兴';
 break;
 case 2:
   text ='育才';
 break;
 case 3:
   text ='实验';
 break;
 case 4:
   text ='迎宾';
 break;
 case 5:
   text ='安顺';
 break;
default:
   text= '其他';
}
       }}
       {{text}}小学
           </span>
                <span class="layui-badge">{{item.shi}}室{{item.ting}}厅{{item.wei}}卫</span>


            </p>
            <p> {{layui.util.timeAgo(item.create_time*1000,1)}}
                {{item.truename}}核实
                电话 <a href="tel:{{item.tel}}">{{item.tel}}</a>

            </p>
            <p>备注：{{item.mark||''}}</p>
        </div>
        <div class="layui-card-body" did={{item.id}}>
            <hr>
            {{#  if(d.data.web_auth>90||item.oper==d.data.user_id){ }}
            <span class="layui-btn  layui-btn-xs" data-type='del'>删除</span>
            {{# if(item.is_top==0){ }}
            <span class="layui-btn  layui-btn-xs layui-bg-blue" data-type='mark' fun='top'>置顶</span>
            {{# }else{ }}
            <span class="layui-btn  layui-btn-xs layui-bg-blue" data-type='mark' fun='untop'>取消置顶</span>

            {{#  } }}

            <span class="layui-btn  layui-btn-xs layui-bg-blue" data-type='mark' fun='stop'>停售</span>
            <span class="layui-btn  layui-btn-xs layui-bg-blue" data-type='shou'>售</span>
            <span class="layui-btn  layui-btn-sm site-demo-btn" data-type='edit' did="{{item.id}}">编辑</span>




            {{# } }}
        </div>
    </div>
    {{#  }); }}


</script>
<script type="text/javascript">
    layui.use(['admin','laytpl','layer','laypage','view','util','form'], function(){
        var $ = layui.$
            ,laypage=layui.laypage
            ,admin=layui.admin
            ,view=layui.view
            ,router = layui.router()
            ,laytpl=layui.laytpl
            ,layer=layui.layer
        form=layui.form;

        var roomView=function(res){
            var getTpl = roomtpl.innerHTML;
            laytpl(getTpl).render(res, function(html){
                $("#roomlist").html(html);
            });
        }

        var roomshow=function(page){
            admin.req({
                type:'post'
                ,url:'/api/room/json'
                ,data:{page:page||1
                    ,key:router.search//这里获取提交到路由的关键字段，然后后台获取
                }
                ,done:function(res){

                    if(res.status=='0'){
                        layui.common.noauth();
                    }else{

                        roomView(res);
                        laypage.render({
                            elem:'pager'
                            ,count:res.data.list.total
                            ,limit:20
                            ,curr:page
                            ,jump:function(e,first){
                                if(!first){
                                    roomshow(e.curr);
                                }
                            }

                        });
                    }

                    $('.layadmin-tabsbody-item').scrollTop(0);


                }
            });
        }
        roomshow();
        var active={
            add:function(){

                admin.popup.roomadd=admin.popup({
                    area:['800px','600px']
                    ,title:'添加房源'
                    ,success:function(){
                        view(this.id).render('room/room/add');
                    }

                });
                var device = layui.device();

                (device.android||device.ios)&&layer.full(admin.popup.roomadd);

                return admin.popup.roomadd;
            },
            edit: function(){

                var did=$(this).attr('did');
                admin.popup.roomedit=admin.popup({
                    area:['800px','600px']
                    ,title:'编辑房源'
                    ,success:function(){
                        view(this.id).render('room/room/edit',{id:did});
                    }

                });
                var device = layui.device();

                (device.android||device.ios)&&layer.full(admin.popup.roomedit);

                return admin.popup.roomedit;

            },
            search: function(){
                var tpl = demo1.innerHTML;

                abc=admin.popup({
                    area:['300px','550px']
                    ,
                    id: 'LAY-popup-test1'
                    ,success: function(){
                        view(this.id).send(tpl);
                        form.render();
                        form.on('submit(shaixuan)',function(data){//这里把弹出框表单提交到router
                            var t='/room/room//';

                            for(var p in data.field){
                                t=t + p + "=" + data.field
                                    +'/';
                            }
                            location.hash=t;

                            return false;

                        });
                    }
                });

            },
            del: function(){
                var did=$(this).parent().attr('did');
                layer.confirm('您真想删除？', {
                    btn: ['是的','不删'] //按钮
                }, function(){

                    admin.req({
                        url:'/api/room/del/id/'+did
                        ,data:{}
                        ,done:function(res){

                            if(res.data=='1'){
                                // layer.close(admin.popup.roomadd);
                                admin.events.refresh()
                            }
                            layer.msg(res.msg);
                        }
                    });
                }, function(){
                    layer.msg('好的', {
                        time: 2000, //20s后自动关闭

                    });
                });


            },
            mark:function(){
                var did=$(this).parent().attr('did');
                var fun=$(this).attr('fun');
                admin.req({
                    url:'/api/room/mark'
                    ,data:{id:did,m:fun}
                    ,done:function(res){

                        if(res.data=='1'){
                            // layer.close(admin.popup.roomadd);
                            admin.events.refresh()
                        }
                        layer.msg(res.msg);
                    }
                });

            },
            uncheck:function(){
                admin.popup.roomuncheck=admin.popup({
                    id:'room-room-uncheck'
                    ,area:['800px','600px']
                    ,title:'核实房源'
                    ,success:function(){
                        view(this.id).render('room/room/uncheck');
                    }

                });
                var device = layui.device();

                (device.android||device.ios)&&layer.full(admin.popup.roomuncheck);

                return admin.popup.roomuncheck;

            }
        }
        $('#room-room').on('click','.layui-btn', function(){
            var type = $(this).data('type');
            active[type] && active[type].call(this);
        });



    });




</script>